/**
 * 
 */
package com.miolr.module.core.service;

import javax.inject.Named;

import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.miolr.core.service.local.LocalGenericService;
import com.miolr.module.core.dao.UserDao;
import com.miolr.module.core.model.User;

/**
 * @author iday
 * 
 */
@Named
@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
public class UserService extends LocalGenericService<UserDao, User> implements
		UserDetailsService {

	@Transactional(propagation = Propagation.REQUIRED)
	public void updateUser(User user) {
		this.dao.update(user);
	}

	@Override
	public User loadUserByUsername(String username)
			throws UsernameNotFoundException {
		User u = this.dao.findbyUsername(username);
		if (u == null) {
			throw new UsernameNotFoundException(username);
		}
		this.dao.initLazeProperties(u, "authorities");
		return u;
	}

}
